
from tkinter import *

app = Tk()
app.title("模拟登录系统")
app.geometry("900x380")

# label元素创建方法
def label_gen(label_name, text_info, x, y):
    label_name = Label(app, text = text_info)
    label_name.place(x = x, y = y)
    return label_name

# input元素创建方法
def input_gen(input_name, textvariable, width, x, y):
    input_name = Entry(app, textvariable = textvariable, width = width)
    input_name.place(x = x, y = y)
    return input_name

copyright_label = Label(app, text = "广雅中学 @ copyrite")
copyright_label.pack(side = "bottom")

pic_path = r'C:/Users/a/Desktop/test01.gif'
canvas = Canvas(app)
image_file = PhotoImage(file = pic_path)
canvas.create_image(0, 0, anchor = "nw", image = image_file)
canvas.place(x = 0, y = 0, width = 600, height = 360)

# login_title = Label(app, text = "登录页面", font=('微软雅黑',12))
# login_title.place(x = 620, y = 150)
login_title = label_gen("login_title", "登录页面", 620, 150)

# name_label = Label(app, text = "用户名：")
# name_label.place(x = 620, y = 200)
name_label = label_gen("name_label", "用户名", 620, 200)

# name_input = Entry(app, textvariable = name_label, width = 20)
# name_input.place(x = 670, y = 200)
name_input = input_gen("name_input", name_label, 20, 670, 200)

# pwd_label = Label(app, text = "密  码：")
# pwd_label.place(x = 620, y = 230)
pwd_label = label_gen("pwd_label", "密 码：", 620, 230)

# pwd_input = Entry(app, textvariable = pwd_label, width = 20)
# pwd_input.place(x = 670, y = 230)
pwd_input = input_gen("pwd_input", pwd_label, 20, 670, 230)

def login_demo():
    msg = ""
    name = name_input.get()
    pwd = pwd_input.get()
    if (name == "") or (pwd == ""):
        msg = "用户名或者密码不能为空"
    elif (name != "admin") or (pwd != "111"):
        msg = "用户名或密码错误"
    elif (name == "admin") and (pwd == "111"):
        msg = "登陆成功"
    else:
        msg = "请录入登录信息"
    msg = msg.center(14, "=")
    login_info = Label(app, text = msg)
    login_info.place(x = 620, y = 260)

login_submit = Button(app, text = "登录", command = login_demo)
login_submit.place(x = 620, y = 280)
# def button_gen(text, command, x, y):
#     login_submit = Button(app, text = text, command = command)
#     login_submit.place(x = x, y = y)
# button_gen("等", "login_demo", 620, 280)

login_quit = Button(app, text = "退出", command = app.quit)
login_quit.place(x = 660, y = 280)

app.mainloop()